package pers.fjl.test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import pers.fjl.common.entity.QueryPageBean;
import pers.fjl.common.po.Supply;
import pers.fjl.common.vo.SupplyVo;
import pers.fjl.test.dao.SupplyDao;
import pers.fjl.test.service.SupplyService;

import javax.annotation.Resource;

@Service
public class SupplyServiceImpl extends ServiceImpl<SupplyDao, Supply> implements SupplyService {
    @Resource
    private SupplyDao supplyDao;

    @Cacheable(value = {"SupplyMap"})
    public Page<SupplyVo> findPage(QueryPageBean queryPageBean) {
        //设置分页条件
        Page<SupplyVo> page = new Page<>(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        //设置查询条件
        QueryWrapper<Supply> wrapper = new QueryWrapper<>();
        if (queryPageBean.getQueryString() != null) {  //不为空，则代表是根据用户名条件查询
            //查询总记录数
            page.setTotal(supplyDao.selectSearchCount(queryPageBean.getQueryString()));
            page.setRecords(supplyDao.searchBySupplier(queryPageBean.getQueryString()));
            return page;
        }
        //执行全部查询
        page.setRecords(supplyDao.getAllSupply());
        //查询总记录数
        page.setTotal(supplyDao.selectCount(null));
        return page;
    }
}
